var config=require('../config/index');

const mongoose = require('mongoose');
//var connect;
module.exports=function(cb){
    // if(connect){
    //     return connect;
    // }
    connect=mongoose.connect(config.mongodb,function(err){
        if(err){
            console.error(err);
        }else{
            console.log('连接成功');
        }
        cb && cb();
    })
    const db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function () {
        // we're connected!
    });
    //return connect;
}